//
//  FlipsideViewController.m
//  memory
//
//  Created by Storm Christoph on 12/23/09.
//  Copyright __MyCompanyName__ 2009. All rights reserved.
//

#import "FlipsideViewController.h"

@implementation FlipsideViewController

@synthesize delegate, labelTimeValue, sliderTimeValue, gameAreaSize, cardsToCompare;
@synthesize optionsSecondsToRun, optionsCardsToCompare, optionsNrOfCards;

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];
	
	sliderTimeValue.value = 60.0;
	labelTimeValue.text = @"60 seconds";
}


- (IBAction)done {
	
	self.optionsSecondsToRun = (int)sliderTimeValue.value;
	
	switch(gameAreaSize.selectedSegmentIndex)
	{
		case 0: // 4x4
			self.optionsNrOfCards = 16;
			self.optionsCardsToCompare = 2;
			break;
		case 1: // 5x5
			self.optionsNrOfCards = 20;
			self.optionsCardsToCompare = 2;
			break;
		case 2: // 3x3
			self.optionsNrOfCards = 9;
			self.optionsCardsToCompare = 2;
			break;
		default:
			self.optionsNrOfCards = 16;
			self.optionsCardsToCompare = 2;
			break;
	}
	
	
	
	[self.delegate flipsideViewControllerDidFinish:self];	
}

- (IBAction)timeValueChanged {

	NSString *time = [NSString stringWithFormat:@"%d seconds", (int)sliderTimeValue.value];
	labelTimeValue.text = time;
	
}

- (IBAction)gameAreaSizeChanged {
	
	[cardsToCompare setEnabled:NO forSegmentAtIndex:0];
	[cardsToCompare setEnabled:NO forSegmentAtIndex:1];
	
	switch(gameAreaSize.selectedSegmentIndex)
	{
		case 0: // 4x4
			cardsToCompare.selectedSegmentIndex = 0;
			[cardsToCompare setEnabled:YES forSegmentAtIndex:0];
			break;
		case 1: // 5x5
			cardsToCompare.selectedSegmentIndex = 0;
			[cardsToCompare setEnabled:YES forSegmentAtIndex:0];
			break;
		case 2: // 3x3
			cardsToCompare.selectedSegmentIndex = 1;
			[cardsToCompare setEnabled:YES forSegmentAtIndex:1];
			break;
		default:
			cardsToCompare.selectedSegmentIndex = 0;
			[cardsToCompare setEnabled:YES forSegmentAtIndex:0];
			break;
	}	
		
}

/*
 // Override to allow orientations other than the default portrait orientation.
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 // Return YES for supported orientations
 return (interfaceOrientation == UIInterfaceOrientationPortrait);
 }
 */

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}

@end
